package com.example.gokchinesefoodmappcdev.dao;



import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.gokchinesefoodmappcdev.entity.SysRole;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface SysRoleDao extends BaseMapper<SysRole> {

    @Select("SELECT sr.* FROM sys_user su LEFT JOIN sys_user_role sur ON su.user_id = sur.user_id LEFT JOIN" +
            " sys_role sr ON sur.role_id = sr.role_id WHERE su.username = #{userName}")
    List<SysRole> findRolesByUserName(String userName);


    @Select("SELECT sr.role_id,sr.role_name FROM sys_user su LEFT JOIN sys_user_role sur ON su.user_id = sur.user_id LEFT JOIN" +
            " sys_role sr ON sur.role_id = sr.role_id WHERE su.user_id = #{userId}")
    List<SysRole> findRoleIdAndRoleNameByUserId(Integer userId);


    @Select("SELECT sr.* FROM sys_menu sm LEFT JOIN sys_role_menu srm ON sm.menu_id = srm.menu_id LEFT JOIN" +
            " sys_role sr ON srm.role_id = sr.role_id WHERE sm.menu_id= #{menuId}")
    List<SysRole> findRolesByMenuId(Integer menuId);

}
